﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdminLibrary
{
    public class Admin
    {
        //Lists to save the instances of each class
        IList<AMP_User> students = new List<AMP_User>();
        IList<AMP_Subject> subjects = new List<AMP_Subject>();
        IList<AMP_Classroom> classrooms = new List<AMP_Classroom>();
        IList<AMP_Content> cont = new List<AMP_Content>();

        public void Add_Classroom(int classroomId, int seats, int computers)
        {
            var newClass = new AMP_Classroom();//Create new instance of the AMP_Classroom class
            newClass.ClassroomID = classroomId;//Fill the propertieswith the given values sent from client
            newClass.Seats = seats;
            newClass.Computers = computers;
            classrooms.Add(newClass);//Add the classroom to the list
            SaveOrUpdateClassroom(newClass);//ORM tool method to insert the new classroom to the database
        }

        public void Add_Student(int studentID, string name, string surname, object avatar) // Added parameters
        {
            var newStudent = new AMP_User();
            newStudent.UserID = studentID;
            newStudent.Name = name;
            newStudent.Surname = surname;
            newStudent.Avatar = avatar;
            students.Add(newStudent);
            SaveOrUpdateUser(newStudent);
        }

        public void Remove_Student(int studentID)
        {
            foreach (var student in students)
            {
                if (student.UserID == studentID)
                {
                    students.Remove(student);
                    DeleteUser(student);
                }
            }
        }

        public void Update_Student(int studentID, string name, string surname, object avatar) // Added parameters
        {
            foreach (var student in students)
            {
                if (student.UserID == studentID)
                {
                    student.Name = name;
                    student.Surname = surname;
                    student.Avatar = avatar;
                    SaveOrUpdateUser(student);
                }
            }
        }

        public void Add_Subject(int ClassroomID, int userID, int subjectId, string subjectIcon, string subjectName, string subjectDescription, int subjectState, int subjectMark, int totalCredits, string detailedDescription, IList<AMP_Subject> required) // Added parameters
        {
            var newSubject = new AMP_Subject();
            newSubject.UserID = userID;
            newSubject.SubjectId = subjectId;
            newSubject.SubjectIcon = subjectIcon;
            newSubject.SubjectName = subjectName;
            newSubject.SubjectDescription = subjectDescription;
            newSubject.SubjectState = subjectState;
            newSubject.SubjectMark = subjectMark;
            newSubject.TotalCredits = totalCredits;
            newSubject.DetailedDescription = detailedDescription;
            newSubject.Required = required;
            subjects.Add(newSubject);
            SaveOrUpdateSubject(newSubject);
        }

        public void Remove_Subject(int SubjectId)
        {
            foreach (var subject in subjects)
            {
                if (subject.SubjectId == SubjectId)
                {
                    subjects.Remove(subject);
                    DeleteSubject(subject);
                }
            }
        }

        public bool Insert_Content(int conID, string name, string con)
        {
            try
            {
                AMP_Content c = new AMP_Content();
                c.ContentID= conID;
                c.ConstentName = name;
                c.TheContent = con;
                cont.Add(c);
                SaveOrUpdateContent(c);
                return true;
            }
            catch
            {
                return false;
            }
        }


        public bool Alter_Contents(AMP_Content con)
        {
            try
            {
                SaveOrUpdateContent(con);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool Delete_Content(AMP_Content con)
        {
            try
            {
                DeleteContent(con);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public IList<AMP_Content> Constents()
        {
            cont = GetContents();
            return cont;
        }

        public AMP_Content SpecificContent(int conID)
        {
            AMP_Content con = new AMP_Content();
            con = GetContent(conID);
            return con;
        }

        public List<AMP_Subject> get_schedule(int studentID) //get the schedule of an existing student
        {
            var schedule = new List<AMP_Subject>();
            foreach (var subject in subjects)
            {
                if (subject.UserID == studentID)
                {
                    schedule.Add(subject);
                }
            }
            return schedule;
        }
    }
}
